package com.cloud.thelen.wallpaper.Adapter;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.FragmentActivity;

import com.cloud.thelen.wallpaper.AllAdapter.BaseRecyclerAdapter;
import com.cloud.thelen.wallpaper.AllAdapter.BaseRecyclerHolder;
import com.cloud.thelen.wallpaper.R;
import com.cloud.thelen.wallpaper.WallpaperActivity;

public class WallpaperAdapter extends BaseRecyclerAdapter<String> {

    private int type;

    private final static int Horizontal = 2;

    private final static int Vertical = 1;

    private final static int FullScreen = 3;

    private View view;

    public WallpaperAdapter(FragmentActivity activity, int number) {
        super(activity, R.layout.all_item);
        type = number;
    }

    @Override
    protected void convert(BaseRecyclerHolder holder, String data) {
        ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
        if (type == Horizontal) {
            params.width = 330;
        } else if (type == Vertical) {
            params.width = 280;
            params.height = 520;
        }
        holder.itemView.setLayoutParams(params);
        holder.setImage(R.id.image, activity, data);
        holder.itemView.setOnClickListener(l -> {
            if (type == FullScreen) {
                view.setVisibility(View.VISIBLE);
            } else {
                Intent intent = new Intent(activity, WallpaperActivity.class);
                intent.putExtra("number", items.indexOf(data));
                intent.putStringArrayListExtra("links", getData());
                activity.startActivity(intent);
            }
        });
    }

    public void setView(View view) {
        this.view = view;
    }
}
